<h1>View Batch "<?php echo $batch->getName()?>"</h1>

<?php //include_stylesheets_for_form($form) ?>
<?php //include_javascripts_for_form($form) ?>

  <table>
    <tbody>
      <?php //echo $form->renderGlobalErrors() ?>
      <tr>
        <th>Name: </th>
        <td><?php echo $batch->getName() ?></td>
      </tr>
      <tr>
        <th>Start Date: </th>
        <td><?php echo MyDateTime::frommysql($batch->getStartdate())->toprettydate() ?></td>
      </tr>
      <tr>
        <th>Grown Date: </th>
        <td><?php echo MyDateTime::frommysql($batch->getGrowndate())->toprettydate() ?></td>
      </tr>
      <tr>
        <th>Processed Date: </th>
        <td><?php echo MyDateTime::frommysql($batch->getProcesseddate())->toprettydate() ?></td>
      </tr>
      <tr>
        <th>Marketed Date: </th>
        <td><?php echo MyDateTime::frommysql($batch->getMarketeddate())->toprettydate() ?></td>
      </tr>
      <tr>
        <th>End Date: </th>
        <td><?php echo MyDateTime::frommysql($batch->getEnddate())->toprettydate() ?></td>
      </tr>
      <tr>
        <th>No. of Recepients: </th>
        <td><?php echo count($batch->getParticipations()) ?></td>
      </tr>
    </tbody>
    <tfoot>
      <tr>
        <td colspan="2">
          &nbsp;<?php echo link_to('Edit', 'batch/edit?id='.$batch->getid()) ?>
          &nbsp;<?php echo link_to('Delete', 'batch/delete?id='.$batch->getid(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
          <br>
          &nbsp;<?php echo link_to("Return to Program",'program/show?id='.$batch['program_id']) ?>
          <br>
          &nbsp;<?php echo link_to("Return to Batches List",'batch/index') ?>
        </td>
      </tr>
    </tfoot>
  </table>

<br>
<!--new participation-->
  <?php $participation=new Participation();$participationform=new ParticipationForm($participation); ?>
  <?php echo form_tag_for($participationform, 'participation/add') ?>
    <?php echo $participationform->renderHiddenFields() ?>
    <input type="hidden" name="batch_id" id="batch_id" value="<?php echo $batch->getId()?>" />

    <?php if ($participationform->hasGlobalErrors()): ?>
      <?php echo $participationform->renderGlobalErrors() ?>
    <?php endif; ?>
  <table>
      <tr>
        <td>New Participant ID:</td>
      </tr>
      <tr>
        <td>
          <input name="recepient_id" id="recepient_id"/>
        </td>
        <td><input type="submit" value="Save" /></td>
      </tr>
  </table>
</form><br>

  <table>
    <tbody>
      <tr valign=top>
        <th><?php echo 'Recepient' ?></th>
        <th> | </th>
        <th><?php echo 'Town' ?></th>
        <th> | </th>
        <th><?php echo 'Inputs' ?></th>
        <th> | </th>
        <th><?php echo 'Inputs Delivered' ?></th>
        <th> | </th>
        <th><?php echo 'Status' ?></th>
        <th> | </th>
        <th><?php echo 'Set Status' ?></th>
        <th> | </th>
        <th><?php echo 'Show' ?></th>
        <th> | </th>
        <th><?php echo 'Edit' ?></th>
        <th> | </th>
        <th><?php echo 'Delete' ?></th>
      </tr>
      <?php foreach($batch->getParticipations() as $item){ 
      ?>
      <tr>
        <td><?php echo $item->getRecepient() ?></td>
        <td> | </td>
        <td><?php echo $item->getRecepient()->getTown() ?></td>
        <td> | </td>
        <td><?php echo $item->getInputString() ?></td>
        <td> | </td>
        <td><?php 
              if($item->getInputdeliverydate())
              {
                echo MyDateTime::frommysql($item->getInputdeliverydate())->toprettydate();
              }
              else
              {
                $item->setInputdeliverydate(MyDateTime::today()->tomysql());
                $itemform=new ParticipationForm($item->getRawValue());
                echo form_tag_for($itemform, 'participation/setdeliverydate');
                echo $itemform->renderHiddenFields();
                echo '<input type="hidden" name="id" id="id" value='.$item->getId().'/>';
                echo $itemform["inputdeliverydate"];
                echo '<input type="submit" value="Save" />';
                echo '</form>';
              }
              
              ?></td>
        <td> | </td>
        <td><?php echo $item->getStatus() ?></td>
        <td> | </td>
        <td><?php if($item->getNextStatus())echo " ".link_to("(Set as ".$item->getNextStatus().")","participation/nextstatus?id=".$item["id"]); ?></td>
        <td> | </td>
        <td><?php echo link_to("Show",'participation/show?id='.$item['id']) ?></td>
        <td> | </td>
        <td><?php echo link_to("Edit",'participation/edit?id='.$item['id']) ?></td>
        <td> | </td>
        <td><?php echo link_to('Delete', 'participation/delete?id='.$item['id'], array('method' => 'delete', 'confirm' => 'Delete participation of: '.$item->getRecepient().' in batch "'.$batch.'": Are you sure?')) ?></td>
      </tr>
      <?php } ?>
  </table>
  

